import com.pojo.Employee;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = session.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey",(long) 1);
        System.out.println(employee);
        session.commit();//提交事务
        session.close();//关闭链接
    }
    @Test
    public void addEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setEname("王八");
        employee.setEage(18);
        employee.setEposition("员工");
        int rows = session.insert("com.mapper.EmployeeMapper.insert",employee);
        System.out.println(rows);
        session.commit(); //提交事务
        session.close(); //关闭链接
    }
    @Test
    public void updateEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        Employee employee = new Employee();
        employee.setEid(4);
        employee.setEname("周其");
        employee.setEage(20);
        employee.setEposition("员工");
        int rows = session.
                update("com.mapper.EmployeeMapper.updateByPrimaryKeySelective",employee);
        System.out.println(rows);
        session.commit();
        session.close();
    }
    @Test
    public void deleteEmployeeTest(){
        SqlSession session = MyBatisUtils.getSession();
        int rows = session.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey",3L);
        System.out.println(rows);
        session.commit();
        session.close(); 
    }
}
